package com.mingliu.transactionalevent.listener;

import com.mingliu.transactionalevent.model.InsAsset;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
public class InsAssetListener {

    @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
    public void onMessage1(InsAsset insAsset){
        System.out.println(Thread.currentThread().getName() + "-onMessage1:事务开始");
    }

    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void onMessage2(InsAsset insAsset){
        System.out.println(Thread.currentThread().getName() + "-onMessage2:事务提交");
    }

    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION)
    public void onMessage3(InsAsset insAsset){
        System.out.println(Thread.currentThread().getName() + "-onMessage3:事务结束");
    }

    @TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK)
    public void onMessage4(InsAsset insAsset){
        System.out.println(Thread.currentThread().getName() + "-onMessage4:事务回滚");
    }
}
